package mypackage;

import java.util.Random;

public class Role {
    private String name;
    private int blood;

    public Role() {
    }

    public Role(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return blood
     */
    public int getBlood() {
        return blood;
    }

    /**
     * 设置
     * @param blood
     */
    public void setBlood(int blood) {
        this.blood = blood;
    }

    public void attack(Role r2){
        Random r=new Random();
        int hurt=r.nextInt(20)+1;
        int life=r2.getBlood()-hurt;
        if(life<0){
            life=0;
        }
        r2.setBlood(life);
        System.out.println(this.name+"攻击了"+r2.getName()+",造成了"+hurt+"点伤害,"
                +r2.getName()+"剩余了"+life+"点血量");
    }
}
